import { Request } from '../utils/request';
import { ApiResponse, Post, PaginationParams, PaginationResult } from '../types';

export class PostApi {
  constructor(private request: Request) {}

  /**
   * 获取帖子列表
   */
  async getPosts(params: PaginationParams): Promise<ApiResponse<PaginationResult<Post>>> {
    return this.request.get('/api/posts', { params });
  }

  /**
   * 获取帖子详情
   */
  async getPostDetail(id: number): Promise<ApiResponse<Post>> {
    return this.request.get(`/api/posts/${id}`);
  }

  /**
   * 创建帖子
   */
  async createPost(data: { title: string; content: string }): Promise<ApiResponse<Post>> {
    return this.request.post('/api/posts', data);
  }

  /**
   * 更新帖子
   */
  async updatePost(id: number, data: { title?: string; content?: string }): Promise<ApiResponse<Post>> {
    return this.request.put(`/api/posts/${id}`, data);
  }

  /**
   * 删除帖子
   */
  async deletePost(id: number): Promise<ApiResponse<void>> {
    return this.request.delete(`/api/posts/${id}`);
  }

  /**
   * 点赞帖子
   */
  async likePost(id: number): Promise<ApiResponse<void>> {
    return this.request.post(`/api/posts/${id}/like`);
  }

  /**
   * 取消点赞
   */
  async unlikePost(id: number): Promise<ApiResponse<void>> {
    return this.request.delete(`/api/posts/${id}/like`);
  }
} 